package com.tf_cut.admin.common.pojo;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一返回对象
 */

@Data
public class ApiResult<T> implements Serializable {
    /**
     * 通信数据
     */
    private T data;
    /**
     * 通信状态
     */
    private int code = 0;
    /**
     * 通信描述
     */
    private String msg = "操作成功";

    /**
     * 通过静态方法获取实例
     */
    public static <T> ApiResult<T> of(T data) {
        return new ApiResult<>(data);
    }

    public static <T> ApiResult<T> of(T data, int code) {
        return new ApiResult<>(data, code);
    }

    public static <T> ApiResult<T> of(T data, int code, String msg) {
        return new ApiResult<>(data, code, msg);
    }

    @Deprecated
    public ApiResult() {

    }

    private ApiResult(T data) {
        this.data = data;
    }

    private ApiResult(T data, int code) {
        this.data = data;
        this.code = code;
    }

    private ApiResult(T data, int code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

}
